package com.wxapp.admin.service.controller;


import com.wxapp.admin.api.pojo.vo.login.QLoginVo;
import com.wxapp.admin.service.service.LoginService;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.AccessLimit;
import com.wxapp.common.core.annotation.User;
import com.wxapp.common.core.filter.except.ThrowMyException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@Tag(name = "登录")
public class LoginController extends IBaseController {
    private final LoginService loginService;

    /**
     * 登录对前端开放
     */
    @PostMapping("/login")
    @AccessLimit(name = "#qLoginVo.loginName",seconds = 10,isLogin = false)
    @Operation(summary = "登录接口")
    public ResultVm<String> login(@RequestBody @Validated QLoginVo qLoginVo) throws ThrowMyException {
        return loginService.login(qLoginVo,getRequest());
    }
    /**
     * 推出登录
     */
    @PutMapping("logOff")
    @Operation(summary = "退出登录")
    public ResultVm<String> logOff(@Schema(hidden = true) @User UserVo userVo){
        return loginService.logOff(userVo);
    }
}
